
import 'dart:convert';

main() {
  //把JSON字符串解析为Dart对象
  String s = '{"ename":"Tom", "age": 18}';    //JSON格式的字符串
  var obj = jsonDecode(s);    //类似于JS中的JSON.parse()

  print(obj is Map);          //jsonDecode()返回值是Map或List
  print(obj);
  print(obj['ename']);
  print(obj['age']);

  //把Map或List序列化为JSON字符串
  Map e = {'ename':'King', 'age':50};
  String str = jsonEncode(e); //类似于JS中的JSON.stringify()
  print(str is String);
  print(str);
}
